package com.whfc.ms.api.fuum.service.impl;

import com.whfc.common.exception.BizException;
import com.whfc.common.result.ResultEnum;
import com.whfc.fuum.entity.AppQualification;
import com.whfc.fuum.service.AppQualificationService;
import com.whfc.ms.api.fuum.service.MsQualificationService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 资质管理服务实现类
 *
 * @author dzg
 * @since 2025-09-23
 */
@Slf4j
@Service
public class MsQualificationServiceImpl implements MsQualificationService {

    @DubboReference(interfaceClass = AppQualificationService.class, version = "1.0.0")
    private AppQualificationService appQualificationService;

    @Override
    public AppQualification getById(Integer id) {
        AppQualification qualification = appQualificationService.getById(id);
        if (qualification == null) {
            throw new BizException(ResultEnum.FAILURE.getCode(), "资质不存在");
        }
        return qualification;
    }

    @Override
    public List<AppQualification> list(String qualificationName, Integer unitId) {
        return appQualificationService.list(qualificationName, unitId);
    }

    @Override
    public boolean save(AppQualification qualification) {
        boolean result = appQualificationService.save(qualification);
        if (!result) {
            throw new BizException(ResultEnum.FAILURE.getCode(), "新增失败");
        }
        return result;
    }

    @Override
    public boolean update(AppQualification qualification) {
        AppQualification existingQualification = appQualificationService.getById(qualification.getId());
        if (existingQualification == null) {
            throw new BizException(ResultEnum.FAILURE.getCode(), "资质不存在");
        }
        boolean result = appQualificationService.update(qualification);
        if (!result) {
            throw new BizException(ResultEnum.FAILURE.getCode(), "更新失败");
        }
        return result;
    }

    @Override
    public boolean delete(Integer id) {
        boolean result = appQualificationService.delete(id);
        if (!result) {
            throw new BizException(ResultEnum.FAILURE.getCode(), "删除失败");
        }
        return result;
    }

    @Override
    public boolean deleteBatch(List<Integer> ids) {
        boolean result = appQualificationService.deleteBatch(ids);
        if (!result) {
            throw new BizException(ResultEnum.FAILURE.getCode(), "批量删除失败");
        }
        return result;
    }
}